#include "chat.h"
#include "ui_chat.h"
#include "protocol.h"
#include "client.h"

Chat::Chat(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Chat)
{
    ui->setupUi(this);
}

Chat::~Chat()
{
    delete ui;
}

void Chat::updateShow_LE(QString strMsg)//更新聊天内容显示框
{
    ui->show_TE->append(strMsg);
}

void Chat::on_send_PB_clicked()
{
    QString strMsg = ui->input_LE->text();
    if(strMsg.isEmpty()){
        return;
    }
    QString curName = Client::getInstance().m_strLoginName;
    PDU* pdu = mkPDU(strMsg.size()+1);
    pdu->uiMsgType =ENUM_MSG_TYPE_CHAT_REQUEST;
    memcpy(pdu->caData, curName.toStdString().c_str(), 32);
    memcpy(pdu->caData+32, m_chatName.toStdString().c_str(), 32);
    memcpy(pdu->caMsg, strMsg.toStdString().c_str(), strMsg.size());
    Client::getInstance().sendPDU(pdu);
    ui->input_LE->clear();
}
